<template>
  <div class="login-container">
    <el-card class="login-card">
      <h1 class="login-title">审批系统登录</h1> <!-- Added title -->
      <el-form
          ref="loginForm"
          :model="loginForm"
          label-width="0"
          label-position="top"
      >
        <el-form-item prop="userName">
          <el-input
              v-model="loginForm.userName"
              placeholder="Username"
          />
        </el-form-item>
        <el-form-item prop="password">
          <el-input
              v-model="loginForm.password"
              placeholder="Password"
              type="password"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="login">Login</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import request from "@/request/request";
import {ElMessage} from "element-plus";

export default {
  data() {
    return {
      loginForm: {
        userName: "",
        password: "",
      },
    };
  },
  methods: {
    login() {
      // 发送登录请求
      request
          .post("/login", this.loginForm)
          .then((response) => {
            if (response.code === 200) {
              // 显示成功提示信息
              ElMessage.success("登录成功");
              sessionStorage.setItem("token", response.data); // 将token存储在sessionStorage
              this.$router.push("/home");
            } else {
              // 显示失败提示信息
              ElMessage.error(response.msg);

            }
          })
          .catch((error) => {
            // 处理登录失败或请求错误
            console.error(error);
            // 显示失败提示信息
            ElMessage.error(error);
          });
    },
  },
};
</script>

<style scoped>
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  width: 400px;
  font-size: 18px; /* Increased font size */
}

.login-title {
  font-size: 24px; /* Increased title font size */
}
</style>
